package gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class Notification {
	
	public static void createDialog(String title, String message){
		final JFrame f = new JFrame(title);
		f.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		
		f.setLayout(new BorderLayout());
		f.getContentPane().add(BorderLayout.WEST, new JLabel(Notification.getIcon("dialog")));
		f.getContentPane().add(BorderLayout.NORTH, new JLabel(title));
		f.getContentPane().add(BorderLayout.CENTER,new JTextField(message));
		
		JButton ok = new JButton("OK");
		ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				f.dispose();
			}
		});
		f.getContentPane().add(BorderLayout.SOUTH,ok);
		
		f.pack();
		
		f.setVisible(true);
	}

	public static void createAlertDialog(String title, String alert){
		final JFrame f = new JFrame(title);
		f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		f.setLayout(new BorderLayout());
		f.getContentPane().add(BorderLayout.WEST, new JLabel(Notification.getIcon("alert")));
		f.getContentPane().add(BorderLayout.NORTH, new JLabel(title));
		f.getContentPane().add(BorderLayout.CENTER,new JTextField(alert));
		
		JButton ok = new JButton("OK");
		ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				f.dispose();
			}
		});
		f.getContentPane().add(BorderLayout.SOUTH,ok);
		
		f.pack();
		
		f.setVisible(true);
	}
	
	public static void createErrorDialog(String title, String error){
		final JFrame f = new JFrame(title);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		f.setLayout(new BorderLayout());
		f.getContentPane().add(BorderLayout.WEST, new JLabel(Notification.getIcon("error")));
		f.getContentPane().add(BorderLayout.NORTH, new JLabel(title));
		f.getContentPane().add(BorderLayout.CENTER,new JTextField(error));
		
		JButton ok = new JButton("OK");
		ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		f.getContentPane().add(BorderLayout.SOUTH,ok);
		
		f.pack();
		
		f.setVisible(true);
	}
	
	public static void createMessageDialog(String title, String message){
		final JFrame f = new JFrame(title);
		f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		f.setLayout(new BorderLayout());
		f.getContentPane().add(BorderLayout.WEST, new JLabel(Notification.getIcon("message")));
		f.getContentPane().add(BorderLayout.NORTH, new JLabel(title));
		f.getContentPane().add(BorderLayout.CENTER,new JTextField(message));
		
		JButton ok = new JButton("OK");
		ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				f.dispose();
			}
		});
		f.getContentPane().add(BorderLayout.SOUTH,ok);
		
		f.pack();
		
		f.setVisible(true);
	}
	
	public static ImageIcon getIcon(String iconName){
		Notification n = new Notification();
		java.net.URL imgURL = n.getClass().getResource("../resources/icons/"+iconName+".png");
		ImageIcon img = null;
		if (imgURL != null) 
			 img = new ImageIcon(imgURL);
		
		return img;
	}
	
}
